package com.xfpp.javaDemo.strategy;

public class DataSorter {
	public static void sort(Comparable[] a) {
		for (int i = a.length; i > 0; i--) {
			for (int j = 0; j < i-1; j++) {
				if(a[j].compareTo(a[j+1]) == 1 ) {
					swap(a,j,j+1);
				}
			}
		}
	}
	
	private static void swap(Comparable[] a, int x, int y) {
		Comparable temp = a[x];
		a[x] = a[y];
		a[y] = temp;
	}
/*	public static void sort(int[] a) {
		for (int i = a.length; i > 0; i--) {
			for (int j = 0; j < i-1; j++) {
				if(a[j] > a[j+1] ) {
					swap(a,j,j+1);
				}
			}
		}
	}
	
	private static void swap(int[] a, int x, int y) {
		int temp = a[x];
		a[x] = a[y];
		a[y] = temp;
	}
*/	
	public static void p(Comparable[] a) {
		for (int i = 0; i < a.length; i++) {
			System.out.print(a[i] + "  ");
		}
	}
}
